package com.ruoyi.web.controller.api.index;

import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.bo.PAboutBo;
import com.ruoyi.system.service.IPAboutService;
import com.ruoyi.system.service.IPEvaluateService;
import com.ruoyi.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author: wk
 * @Date: 2022/7/21 15:10
 * @Version: 1.0
 */
@Api(value = "首页", tags = {"前端-首页信息"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/index")
public class IndexPageController {
    private final ISysUserService userService;
    private final IPAboutService aboutService;
    private final IPEvaluateService evaluateService;

    @ApiOperation(value = "咨询师列表-分页")
    @GetMapping("/get-user-index")
    public TableDataInfo<SysUser> getUserIndex(SysUser user, PageQuery pageQuery) {
        return userService.selectIndexUser(user, pageQuery);
    }

    @ApiOperation(value = "咨询师详情")
    @GetMapping("/get-user-info/{id}")
    public R<Map<String, Object>> getUserInfo(@PathVariable("id") Long id) {
        Map<String, Object> res = new HashMap<>();
        // 咨询师下详情、平台保障、用户评价
        res.put("info", userService.queryUserInfo(id));
        res.put("ensure", aboutService.queryList(new PAboutBo().setType("4")));
        res.put("evaluation", evaluateService.queryByAdviserId(id, null));
        return R.ok(res);
    }
}
